package com.example.ordersystem.service;

import com.example.ordersystem.dao.CustomerDAOByMybatis;
import com.example.ordersystem.domain.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CustomerService {
    @Autowired
    CustomerDAOByMybatis customerDAOByMybatis;

    /**
     * 普通顾客登录
     * @param num 顾客账号
     * @param pwd
     * @return
     */
    public Customer customerLoginCheck(int num, String pwd) {
        return customerDAOByMybatis.customerLoginCheck(num, pwd);
    }

    /**
     * 用户注册
     * @param customer
     */
    public void register(Customer customer) {
        customerDAOByMybatis.register(customer);
    }

    /**
     * 在顾客表中查询，手机号是否已经注册
     * @param tel 手机号
     * @return 0 未注册;1 顾客编号
     */
    public int alreadyRegistered(String tel) {
        Customer customer = customerDAOByMybatis.findByTel(tel);
        if (customer == null) {
            return 0;
        }
        return customer.getNum();
    }

    /**
     * 顾客登录，手机-验证码
     * @param tel 手机号码
     * @return null顾客不存在;non-null 顾客存在
     */
    public Customer customerSMSLoginCheck(String tel) {
        return customerDAOByMybatis.findCustomerByTel(tel);
    }

    /**
     * 顾客修改密码
     * @param num 顾客账号
     * @param newPass 新的密码
     */
    public void modifyPass(int num,String newPass){
        customerDAOByMybatis.modifyPass(num,newPass);
    }
}
